package com.yanqu.road.dao.impl.activity.carptrip;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.carptrip.config.*;
import com.yanqu.road.entity.activity.carptrip.config.CarpTripPvpTopInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class CarpTripConfigDaoImpl extends TempDao {

    private static String getCarpTripEventInfoSql = "select * from `t_s_activity_carp_trip_event` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripEventInfo> getCarpTripEventInfoList(int activityId) {
        List<CarpTripEventInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripEventInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripEventInfo climbTowerEventInfo = new CarpTripEventInfo();
                climbTowerEventInfo.setActivityId(rs.getInt("activityId"));
                climbTowerEventInfo.setId(rs.getInt("id"));
                climbTowerEventInfo.setType(rs.getInt("type"));
                climbTowerEventInfo.setLittleType(rs.getInt("littleType"));
                climbTowerEventInfo.setExParam(rs.getString("exParam"));
                climbTowerEventInfo.setItemId(rs.getInt("itemId"));
                list.add(climbTowerEventInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripLevelInfoSql = "select * from `t_s_activity_carp_trip_level` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripLevelInfo> getCarpTripLevelInfoList(int activityId) {
        List<CarpTripLevelInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripLevelInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripLevelInfo climbTowerLevelInfo = new CarpTripLevelInfo();
                climbTowerLevelInfo.setActivityId(rs.getInt("activityId"));
                climbTowerLevelInfo.setId(rs.getInt("id"));
                climbTowerLevelInfo.setBossId(rs.getInt("bossID"));
                climbTowerLevelInfo.setTemplateId(rs.getInt("templateId"));
                climbTowerLevelInfo.setReward(rs.getString("reward"));
                list.add(climbTowerLevelInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripRoleInfoSql = "select * from `t_s_activity_carp_trip_role` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripRoleInfo> getCarpTripRoleInfoList(int activityId) {
        List<CarpTripRoleInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripRoleInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripRoleInfo data = new CarpTripRoleInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setLevel(rs.getInt("level"));
                data.setExp(new BigInteger(rs.getString("exp")));
                data.setAddEffect(rs.getString("addEffect"));
                //data.setPic(rs.getInt("pic"));
                //data.setArmsPic(rs.getInt("armPic"));
                list.add(data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripTemplateInfoSql = "select * from `t_s_activity_carp_trip_template` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripTemplateInfo> getCarpTripTemplateInfoList(int activityId) {
        List<CarpTripTemplateInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripTemplateInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripTemplateInfo data = new CarpTripTemplateInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                //data.setType(rs.getInt("type"));
                data.setCodeA(rs.getString("codeA"));
                data.setEventList(StringUtils.stringToStringList(rs.getString("event"), "\\|"));
                data.setPicList(StringUtils.stringToStringList(rs.getString("pic"), "\\|"));
                list.add(data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripInfoSql = "select * from `t_s_activity_carp_trip_tower` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripAbilityInfo> getCarpTripInfoList(int activityId) {
        List<CarpTripAbilityInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripAbilityInfo climbTowerInfo = new CarpTripAbilityInfo();
                climbTowerInfo.setActivityId(rs.getInt("activityId"));
                climbTowerInfo.setId(rs.getInt("id"));
                climbTowerInfo.setAbility(rs.getString("ability"));
                list.add(climbTowerInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripPvpTopInfoSql = "select * from `t_s_activity_carp_trip_top` where `activityId`=? ORDER BY `cellNum` ASC";
    public List<CarpTripPvpTopInfo> getCarpTripPvpTopInfoList(int activityId) {
        List<CarpTripPvpTopInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripPvpTopInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripPvpTopInfo carpTripPvpTopInfo = new CarpTripPvpTopInfo();
                carpTripPvpTopInfo.setActivityId(rs.getInt("activityId"));
                carpTripPvpTopInfo.setCellNum(rs.getInt("cellNum"));
                carpTripPvpTopInfo.setAbility(rs.getString("ability"));
                carpTripPvpTopInfo.setPic(rs.getInt("pic"));
                carpTripPvpTopInfo.setReward(rs.getString("reward"));
                list.add(carpTripPvpTopInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripDragonUpInfoSql = "select * from `t_s_activity_carp_trip_dragonup` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripDragonUpInfo> getCarpTripDragonUpInfoList(int activityId) {
        List<CarpTripDragonUpInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripDragonUpInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripDragonUpInfo carpTripDragonUpInfo = new CarpTripDragonUpInfo();
                carpTripDragonUpInfo.setActivityId(rs.getInt("activityId"));
                carpTripDragonUpInfo.setId(rs.getInt("id"));
                carpTripDragonUpInfo.setBorn(rs.getInt("born"));
                carpTripDragonUpInfo.setCondition(rs.getInt("condition"));
                carpTripDragonUpInfo.setPic(rs.getString("pic"));
                carpTripDragonUpInfo.setReward(rs.getString("reward"));
                carpTripDragonUpInfo.setPicScale(rs.getString("picScale"));
                carpTripDragonUpInfo.setRolePic(rs.getInt("rolePic"));
                list.add(carpTripDragonUpInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripDrawUpInfoSql = "select * from `t_s_activity_carp_trip_drawup` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripDrawUpInfo> getCarpTripDrawUpInfoList(int activityId) {
        List<CarpTripDrawUpInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripDrawUpInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripDrawUpInfo carpTripDrawUpInfo = new CarpTripDrawUpInfo();
                carpTripDrawUpInfo.setActivityId(rs.getInt("activityId"));
                carpTripDrawUpInfo.setId(rs.getInt("id"));
                carpTripDrawUpInfo.setLevel(rs.getInt("level"));
                carpTripDrawUpInfo.setExp(rs.getInt("exp"));
                carpTripDrawUpInfo.setCost(rs.getInt("cost"));
                carpTripDrawUpInfo.setShootNum(rs.getInt("shootNum"));
                list.add(carpTripDrawUpInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

    private static String getCarpTripPicInfoSql = "select * from `t_s_activity_carp_trip_pic` where `activityId`=? ORDER BY `id` ASC";
    public List<CarpTripPicInfo> getCarpTripPicInfoList(int activityId) {
        List<CarpTripPicInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCarpTripPicInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CarpTripPicInfo carpTripPicInfo = new CarpTripPicInfo();
                carpTripPicInfo.setActivityId(rs.getInt("activityId"));
                carpTripPicInfo.setId(rs.getInt("id"));
                carpTripPicInfo.setType(rs.getInt("type"));
                carpTripPicInfo.setCode(rs.getInt("code"));
                carpTripPicInfo.setFishId(rs.getInt("fishId"));
                carpTripPicInfo.setFishLv(rs.getInt("fishLv"));
                carpTripPicInfo.setScale(rs.getInt("scale"));
                list.add(carpTripPicInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }
}
